//
//  EndScene.cpp
//  Domino
//
//  Created by Alex on 14-11-16.
//
//

#include "EndScene.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
#include "HelloWorldScene.h"

USING_NS_CC;

using namespace cocostudio::timeline;

Scene* EndScene::createScene()
{
    // 'scene' is an autorelease object
    auto scene = Scene::create();
    
    // 'layer' is an autorelease object
    auto layer = EndScene::create();
    
    // add layer as a child to scene
    scene->addChild(layer);
    
    // return the scene
    return scene;
}

bool EndScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    auto rootNode = CSLoader::createNode("EndScene.csb");
    
    addChild(rootNode);
    
    auto retry_btn = static_cast<Sprite*>(rootNode->getChildByName("retry-btn"));
    
    auto clickEventListener = EventListenerTouchOneByOne::create();
    clickEventListener->onTouchBegan = [this,retry_btn](Touch* t,Event* e){
        if(retry_btn->getBoundingBox().containsPoint(t->getLocation()))
        {
            Director::getInstance()->replaceScene(HelloWorld::createScene());
        }
        return false;
    };
    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(clickEventListener, this);

    
    return true;
}